package com.wuyi.controller;

import com.github.pagehelper.PageInfo;
import com.wuyi.pojo.bo.CollectBO;
import com.wuyi.service.CollectService;
import com.zc.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName CollectController.java
 * @Description 收藏模块相关接口
 * @createTime 2021年11月04日 10:57:00
 */
@Api(value = "收藏",tags = {"用于收藏的相关接口"})
@RestController
@RequestMapping("collect")
public class CollectController {

    public final static Logger logger = LoggerFactory.getLogger(CollectController.class);


    @Autowired
    private CollectService collectService;

    /*@ApiOperation(value = "获取个人收藏列表（可调试）", notes = "获取个人收藏列表（可调试）", httpMethod = "GET")
    @GetMapping("/list")
    public JSONResult list(@ApiParam(name = "userId", value = "用户id", required = true)
                           @RequestParam String userId,
                           @ApiParam(name = "pageNum", value = "第几页", required = true)
                           @RequestParam( required = false,defaultValue = "1")Integer pageNum,
                           @ApiParam(name = "pageSize", value = "一页多少条数据", required = true)
                           @RequestParam( required = false,defaultValue = "10")Integer pageSize) {

        if (null == userId) {
            return JSONResult.errorMsg("系统异常");
        }
        if (null == pageNum) pageNum = 1;
        if (null == pageSize) pageSize = 10;

        PageInfo pageInfo = collectService.list(userId, pageNum, pageSize);

        return JSONResult.ok(pageInfo);
    }*/


    /*@ApiOperation(value = "收藏资源（可调试）", notes = "收藏资源（可调试）", httpMethod = "POST")
    @PostMapping("/add")
    public JSONResult add(@ApiParam(name = "userId", value = "用户id", required = true)
                          @RequestParam String userId,
                          @ApiParam(name = "resourceId", value = "资源Id", required = true)
                          @RequestParam Integer resourceId) {

        if (null == userId) return JSONResult.errorMsg("未登陆");
        if (null == resourceId) return JSONResult.errorMsg("资源失效");
        return collectService.add(userId, resourceId);
    }*/

    @ApiOperation(value = "收藏资源（可调试）", notes = "收藏资源（可调试）", httpMethod = "POST")
    @PostMapping("/add")
    public JSONResult add(@RequestBody CollectBO collectBO) {

        if (StringUtils.isBlank(collectBO.getUserName()) ){
            return JSONResult.errorMsg("userName不能为空");
        }
        if (null == collectBO.getResourceId()) {
            return JSONResult.errorMsg("resource不能为空");
        }
        return collectService.add(collectBO);
    }


    @ApiOperation(value = "取消收藏资源（可调试）", notes = "取消收藏资源（可调试）", httpMethod = "POST")
    @PostMapping("/cancel")
    public JSONResult cancel(@RequestBody CollectBO collectBO) {

        if (null == collectBO.getResourceId()) return JSONResult.errorMsg("资源Id不能为空");
        if (StringUtils.isBlank(collectBO.getUserName())) return JSONResult.errorMsg("userName不能为空");
        return collectService.cancel(collectBO);
    }


}
